﻿using System;
using System.Text;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;
using NIIT.SaoBacDau.Aupi.HospitalManagement.DataAccess;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement.BusinessLogic
{
    public class BL_HR_Employee
    {
        public static int Update(HR_Employee hr_Em)
        {
            int Eror = 0;
            Regex rstring = new Regex(@"^[a-zA-Z\s]{2,30}$");
            Regex rphone = new Regex("^[0-9]{10,11}$");
            Regex remail = new Regex(@"\A\w+@(\w+\.)+\w+\z");
            if (hr_Em.PhoneNumber.Length > 0)
            {
                if (rphone.IsMatch(hr_Em.PhoneNumber) == false)
                    Eror = 2;
                else if (hr_Em.Email.Length > 0)
                {
                    if (remail.IsMatch(hr_Em.Email) == false)
                        Eror = 3;
                    else
                        Eror = DAO_HR_Employee.UpdateEmployee(hr_Em);
                }
            }
            else if (hr_Em.Email.Length > 0)
            {
                if (remail.IsMatch(hr_Em.Email) == false)
                    Eror = 2;
                else
                    Eror = DAO_HR_Employee.UpdateEmployee(hr_Em);
            }
            else
            {
                Eror = DAO_HR_Employee.UpdateEmployee(hr_Em);
            }
            return Eror;
        }

        public static HR_Employee Employee (HR_Employee hr_Em)
        {
            return DAO_HR_Employee.Employee(hr_Em);
        }
    }
}
